<template>
  <div class="error-container">
    <div class="error-content">
      <!-- 错误图标 -->
      <div class="error-icon">
        <svg v-if="error.statusCode === 404" width="120" height="120" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z" stroke="currentColor" stroke-width="2"/>
          <path d="M15 9L9 15" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
          <path d="M9 9L15 15" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
        </svg>
        <svg v-else width="120" height="120" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M12 8V12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
          <path d="M12 16H12.01" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
          <path d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z" stroke="currentColor" stroke-width="2"/>
        </svg>
      </div>

      <!-- 错误信息 -->
      <h1 class="error-code">{{ error.statusCode }}</h1>
      <h2 class="error-message" v-if="error.statusCode === 404">
        页面迷路了...
      </h2>
      <h2 class="error-message" v-if="error.statusCode === 403">
        哎呀，你没有访问的权限！
      </h2>
      <h2 class="error-message" v-if="error.statusCode === 401">
        哎呀，你还未登录！
      </h2>
      <h2 class="error-message" v-if="error.statusCode === 500">
        哎呀，出错了！
      </h2>

      <!-- 操作按钮 -->
      <div class="action-buttons">
        <button class="primary-btn" @click="handleError">
          <span>返回首页</span>
        </button>
        <button class="secondary-btn" @click="goBack">
          <span>返回上一页</span>
        </button>
      </div>

      <!-- 额外帮助 -->
      <div class="help-links">
        <p>需要帮助？<a href="/#">联系支持</a></p>
          
      </div>
    </div>

    <!-- 装饰元素 -->
    <div class="decoration decoration-1"></div>
    <div class="decoration decoration-2"></div>
    <div class="decoration decoration-3"></div>
  </div>
</template>

<script setup>
const props = defineProps({
  error: Object
})

// 设置页面标题
useHead({
  title: props.error.statusCode === 404 
    ? '页面未找到 - 404' 
    : `错误 ${props.error.statusCode} - 系统异常`
})

const errorMessage = computed(() => 
  errorMessages[props.error.statusCode] || 
  props.error.message || 
  '发生了一个未知错误，请稍后再试。'
)

const handleError = () => clearError({ redirect: '/' })

const goBack = () => {
  if (window.history.length > 1) {
    window.history.back()
  } else {
    handleError()
  }
}
</script>

<style scoped>
.error-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: relative;
  overflow: hidden;
  padding: 20px;
}

.error-content {
  text-align: center;
  background: rgba(255, 255, 255, 0.95);
  padding: 3rem;
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 2;
  max-width: 500px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.error-icon {
  margin-bottom: 1.5rem;
  color: #ff4d4f;
  display: flex;
  justify-content: center;
}

.error-code {
  font-size: 4rem;
  font-weight: 700;
  color: #ff4d4f;
  margin: 0 0 0.5rem 0;
  background: linear-gradient(135deg, #ff4d4f, #ff7875);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}

.error-message {
  font-size: 1.8rem;
  font-weight: 600;
  color: #262626;
  margin: 0 0 1rem 0;
  text-align: center;
}

.error-description {
  font-size: 1.1rem;
  color: #595959;
  line-height: 1.6;
  margin: 0 0 2rem 0;
  text-align: center;
  max-width: 400px;
}

.action-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 2rem;
  margin-top: 2rem;
  flex-wrap: wrap;
  width: 100%;
}

button {
  padding: 0.875rem 2rem;
  border: none;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 140px;
}

.primary-btn {
  background: linear-gradient(135deg, #ff4d4f, #ff7875);
  color: white;
  box-shadow: 0 4px 15px rgba(255, 77, 79, 0.3);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(255, 77, 79, 0.4);
}

.secondary-btn {
  background: transparent;
  color: #595959;
  border: 2px solid #d9d9d9;
}

.secondary-btn:hover {
  background: #f5f5f5;
  border-color: #bfbfbf;
  transform: translateY(-2px);
}

.help-links {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #f0f0f0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.help-links p {
  margin: 0 0 0.5rem 0;
  color: #8c8c8c;
  font-size: 0.9rem;
  text-align: center;
}

.links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.help-links a {
  color: #1890ff;
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.3s ease;
  white-space: nowrap;
}

.help-links a:hover {
  color: #40a9ff;
  text-decoration: underline;
}

.divider {
  color: #d9d9d9;
  margin: 0 0.25rem;
}

/* 装饰元素 */
.decoration {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  animation: float 6s ease-in-out infinite;
}

.decoration-1 {
  width: 80px;
  height: 80px;
  top: 20%;
  left: 10%;
  animation-delay: 0s;
}

.decoration-2 {
  width: 120px;
  height: 120px;
  bottom: 15%;
  right: 15%;
  animation-delay: 2s;
}

.decoration-3 {
  width: 60px;
  height: 60px;
  top: 60%;
  left: 20%;
  animation-delay: 4s;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px) rotate(0deg);
  }
  50% {
    transform: translateY(-20px) rotate(180deg);
  }
}

/* 响应式设计 */
@media (max-width: 640px) {
  .error-content {
    padding: 2rem 1.5rem;
    margin: 1rem;
  }
  
  .error-code {
    font-size: 3rem;
  }
  
  .error-message {
    font-size: 1.5rem;
  }
  
  .action-buttons {
    flex-direction: column;
    align-items: center;
  }
  
  button {
    width: 100%;
    max-width: 250px;
  }
  
  .links {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .divider {
    display: none;
  }
  
  .decoration {
    display: none;
  }
}

/* 确保所有文本都居中 */
.error-content > * {
  text-align: center;
  margin-left: auto;
  margin-right: auto;
}
</style>